<template>
  <div>
    <table>
      <div v-for="(i, v) in list" :key="v">
        <tr>
          <td>
            <van-field :label="i.lable" v-model="names[v]" />
          </td>
          <td>
            <select name="" id="" v-model="types[v]">
              <option value="input">输入框</option>
              <option value="radio">单选框</option>
              <option value="checkbox">多选框</option>
              <option value="select">下拉框</option>
              <option value="datetime">日期</option>
              <option value="file">文件</option>
            </select>
          </td>
          <td>
            <van-field label="值" v-model="values[v]" />
            <el-button type="text" @click="getsourse(v)"
              >选择配置资源</el-button
            >
            <!-- <button>选择资源</button> -->
          </td>
        </tr>
      </div>
    </table>
    <van-button @click="add">+</van-button>
    <van-button @click="submit">提交</van-button>
    <div>
      <el-dialog title="选择资源" v-model="dialogTableVisible">
        <el-table :data="tableData" @current-change="handleCurrentChange">
          <el-table-column
          type="index"
            property="name"
            label="Name"

            width="150"
            
          ></el-table-column>
        </el-table>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import axios from '../../http/axios'
export default {
  data() {
    return {
      list: [{ lable: "name" }],
      dialogTableVisible: false,
      gridData: [{'id':1,'name':'请假类型数据源'},{'id':2,'name':'会议地址数据源'}],
      values: {},
      types: {},
      names: {},
      tableData: [],
    };
  },
  methods: {
    getsourse(v) {
      localStorage.setItem("index", v);
      axios("/getresourcedata", "get").then((res) => {
        this.tableData = res.list;
      });
      this.dialogTableVisible = true;
    },
    add() {
      this.list.push({ lable: "name" });
    },
    submit() {
      //获取输入的所有值
      let tlist = [];
      for (var i = 0; i < this.list.length; i++) {
        let dict = {
          lable: this.names[i],
          type: this.typevalues[i],
          values: this.values[i],
        };
        tlist.push(dict);
      }
    },
    handleCurrentChange(val) {
      this.dialogTableVisible = false;
      let index = localStorage.getItem("index");
      this.values[index] = JSON.stringify(val["mes"]);
    },
  },
  mounted() {},
};
</script>

<style>
</style>